#!/bin/sh

# $Id: _initscript_stub.sh,v 1.7 2009-07-23 22:05:47 brian Exp $
# Copyright (c)2012 Brian Manning <brian at xaoc dot org>

# PLEASE DO NOT E-MAIL THE AUTHOR ABOUT THIS SOFTWARE
# The proper venue for questions is the LACK mailing list at:
# http://groups.google.com/linuxack or <linuxack.googlegroups.com>

# picks up things like colorize()
if ! [ -e $LACK_FUNCTIONS ]; then
    LACK_FUNCTIONS="/etc/scripts/lack_functions.sh"
fi # if ! [ -e $LACK_FUNCTIONS ]
source $LACK_FUNCTIONS

ACTION=$1
BINARY=/bin/sed
[ -x "$BINARY" ] || exit 1
BASENAME="generate-fstab"
DESC="Generating custom /etc/fstab file based on volume ID"

# grab the volume ID
#file_parse "/proc/cmdline" "prompt"
#PROMPT=$PARSED
# double check that the prompt command line option was used
if [ "x$PROMPT" = "X" ]; then
    colorize $S_FAILURE "ERROR: 'prompt' not found on kernel command line"
    colorize $S_FAILURE "ERROR: Use the 'prompt' option to pass volume ID"
    colorize $S_FAILURE "ERROR: of encrypted volume at the system boot prompt"
    exit 1
fi

case "$ACTION" in
  vars)
    # echo out what commandline variables are parsed by this script
    echo "${BASENAME}:"
    exit 0
  ;;
  start)
    colorize $S_TIP "${BASENAME}: ${DESC}"
    #/bin/cat /etc/fstab.template | $BINARY "s/XXXXXXXX/${PROMPT}" \
    #    > /etc/fstab
    /bin/cat fstab.template | $BINARY "s/XXXXXXXX/${PROMPT}" \
        > /tmp/fstab
    check_exit_status $? $BASENAME
    ;;
  stop)
    colorize $S_TIP "${BASENAME}: Stopping ${DESC}"
    ;;
  restart|force-reload)
     $0 stop
     $0 start
    ;;
  *)
    echo "Usage: $BASENAME {start|stop|restart|force-reload}" >&2
    exit 3
    ;;
esac

exit 0
# vi: set shiftwidth=4 tabstop=4 filetype=sh :
# конец!
